<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Facades\Image;

class QrPoster extends Model
{
    protected $table = 'qr_poster';
    const TYPE = [
        'doc'=>'doc',
        'lecture' => 'lecture',
        'channel' => 'channel',
    ];

    public static function getQrPoster($qrPoster, $user)
    {
        $params = json_decode($qrPoster->params, true);
        $bg = Image::cache(function ($image) use ($qrPoster) {
            $image->make(Storage::get($qrPoster->path));
        }, 10, true);
        $ewm = Image::make(TicketModel::getQrCode($user->id, TicketModel::TYPE_invite))->resize($params['qr_code_info']['w'],$params['qr_code_info']['h']);
        $bg->insert($ewm, 'top-left', $params['qr_code_info']['x'], $params['qr_code_info']['y']);
        return $bg;
    }

    public function getParamsDataAttribute()
    {
        return json_decode($this->params);
    }
}
